package com.bw.lib_core.network.interceptor;

import com.blankj.utilcode.util.SPUtils;

import java.io.IOException;

import okhttp3.Interceptor;
import okhttp3.Request;
import okhttp3.Response;

public class TokenInterceptor implements Interceptor {

    @Override
    public Response intercept(Chain chain) throws IOException {
        //获取原始请求接口 -> 请求地址，请求方式，请求头 ，请求体
        Request old = chain.request();
        //构建新的对象去修改
        Request.Builder builder = new Request.Builder();
        builder.url(old.url());
        builder.headers(old.headers());
        builder.addHeader("token", SPUtils.getInstance().getString("token"));
        assert old.body() != null;
        builder.post(old.body());
        return chain.proceed(builder.build());
    }
}
